<?php
require RELATIVE_ROOT.'Classes/Abstract_SEssion.php';
/**
 * XiteCode Default Session Handler
 *
 * By default XiteCode uses PHPs default $_SESSION array.
 *
 * @copyright 2006 A.Sleep <a.sleep@asleep.net> under the GNU GPL version 2
 * @author A.Sleep <a.sleep@asleep.net>
 * @access public
 * @package core
 */

class Session extends Abstract_Session {


  /**
   * Triggers session_start()
   */

  public function start()
  {
    session_start();
  }


  /**
   * Sets a variable in the $_SESSION array
   *
   * @param string $name Session value name
   * @param mixed $value Session value contents
   * @return bool
   */

  protected function __set($name, $value)
  {
    return $_SESSION[$name] = $value;
  }


  /**
   * Returns (bool) false or the value of $name
   *
   * WARNING! Will not trigger_error if the value is not set.
   *
   * @param string $name Session value name
   * @return mixed
   */

  protected function __get($name)
  {
    if (!isset($_SESSION[$name])) {
      return false;
    }
    return $_SESSION[$name];
  }


  /**
   * Unsets a variable in the $_SESSION array
   *
   * @param string $name Session value name
   * @return bool
   */

  protected function __unset($name)
  {
    unset($_SESSION[$name]);
  }


  /**
   * Uses the included dBug class to dump the current session
   *
   * Dumping of the session can be done using echo $Session;
   *
   * @see dBug.php
   */

  public function __toString()
  {
    require RELATIVE_ROOT.'Classes/dBug.php';
    new dBug($_SESSION);
    return '';
  }


  /**
   * Adds a value to an array in the session
   *
   * @param string $arrayName Name of the session array
   * @param mixed $value Value to be added to the array
   *
   */

  public function addToArray($arrayName, $value)
  {
    return $_SESSION[$arrayName][] = $value;
  }

}

?>
